$(function () {
    $(".likes img").on("click",function () {
        $(this).attr("src","/img/goodClick.png");
        var objectid=$("#referScript").attr("data");//获取当前书籍的objectid
        // console.log(objectid);
        var events={"eventType":"点赞","value":objectid};
        $.ajax({
            url: "bookDetail/userEvent",
            method: "POST",
            contentType: "application/json;charset=UTF-8",
            data: JSON.stringify(events),
            success: function (result) {
                console.log(result);
                if(result==="like successful"){
                    var newValues=Number($("#likesCount").text())+1;
                    $("#likesCount").text(newValues);
                }
            }
        })
    });
    $(".collection img").on("click",function () {
        $(this).attr("src","/img/collectionClick.png");
        var objectid=$("#referScript").attr("data");//获取当前书籍的objectid
        var events={"eventType":"收藏","value":objectid};
        $.ajax({
            url: "bookDetail/userEvent",
            method: "POST",
            contentType: "application/json;charset=UTF-8",
            data: JSON.stringify(events),
            success: function (result) {
                console.log(result);
                if(result==="collection successful"){
                    var newValues=Number($("#collectionsCount").text())+1;
                    $("#collectionsCount").text(newValues);
                }
            }
        })
    });
    $(".download img").on("click",function () {
        var objectid=$("#referScript").attr("data");//获取当前书籍的objectid
        var events={"eventType":"下载","value":objectid};
        $.ajax({
            url: "bookDetail/userEvent",
            method: "POST",
            // dataType: "json",  若后端传来的不是json数据，success将不执行或者读不到
            contentType: "application/json;charset=UTF-8",
            data: JSON.stringify(events),
            success: function (result) {
                console.log(result);
                if(result==="download successful"){
                    var newValues=Number($("#downloadCount").text())+1;
                    $("#downloadCount").text(newValues);
               ShowMsg("下载成功!")
                    // alert("下载成功!");
                }else{
                    ShowMsg("下载失败！请重试")
                    // alert("下载失败！请重试");
                }
            }
        })
    });
});